<!--
 * @Author: White
 * @description: 热门推荐
 * @LastEditTime: 2021-12-03 18:44:48
-->

<template>
    <div>
        <div class="title" :style="{ 'color': theme.text }">
            <h3>热门推荐</h3>
            <i class="el-icon-arrow-right"></i>
        </div>
        <div class="card-wrapper-loading"
            v-show="loading"
            v-loading="loading"
            element-loading-text="载入中..."
            element-loading-spinner="el-icon-loading"
            element-loading-background="rgba(255, 255, 255)">
        </div>
        <div class="recommend-wrap" v-show="!loading">
            <div class="recommend-item" v-for="(item, index) in songsList" :key="index"
            :style="{ 'color': theme.text }" @click="songListdetail(item.id)">
                <img :src="item.picUrl" alt />
                <p>{{ item.name }}</p>
                <span class="play">{{ keepTwoDecimalFull(item.playCount) }}</span>
            </div>
        </div>
    </div>
</template>

<script>
import { useRouter } from 'vue-router'
import { useStore } from 'vuex'
import { reactive, onMounted, computed, toRefs } from 'vue'
import { getRecommend } from '@/api/music'
import { keepTwoDecimalFull } from '@/utils/index'
export default {
    setup() {
        const router = useRouter()
        const store = useStore()
        const theme = computed(() => store.state.theme)
        const data = reactive({
            loading: false,
            songsList: []
        })
        const getData = async() => {
            data.loading = true
            const res = await getRecommend()
            if (res.data.code === 200) {
                data.songsList = res.data.result.splice(0, 10)
                data.loading = false
            }
        }

        // 歌单详情
        function songListdetail(id){
            router.push({ name: "songListdetail", params: { id: id } });
        }

        onMounted(() => {
            getData()
        })
        return {
            ...toRefs(data),
            songListdetail,
            theme,
            keepTwoDecimalFull
        }
    }
}
</script>

<style lang="scss" scoped>
.title {
    height: 30px;
    display: flex;
    align-items: center;
    h3 {
        line-height: 30px;
        font-size: 16px;
        font-weight: 700;
        text-decoration: none;
    }
}
.card-wrapper-loading {
    z-index: 9;
    top: 0px;
    :deep(.el-loading-spinner) {
        display: flex;
        align-items: center;
        justify-content: center;
    }
    :deep(.el-icon-loading) {
        color: #666;
    }
    :deep(.el-loading-text) {
        margin-left: 2px;
        color: #666;
    }
}
.recommend-wrap {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    margin-bottom: 10px;
    .recommend-item:nth-child(5) {
        margin-right: 0px;
    }
    .recommend-item:nth-child(10) {
        margin-right: 0px;
    }
    .recommend-item {
        width: 170px;
        height: 170px;
        margin-right: 10px;
        margin-bottom: 50px;
        border-radius: 4px;
        position: relative;
        cursor: pointer;
        img {
            width: 170px;
            height: 170px;
            cursor: pointer;
            border-radius: 4px;
        }
        p {
            font-size: 14px;
            font-weight: 400;
            line-height: 20px;
            overflow: hidden;
            text-overflow: ellipsis;
        }
        .play {
            font-size: 14px;
            font-weight: 300;
            line-height: 20px;
            position: absolute;
            top: 10px;
            right: 10px;
            color: #fff;
        }
    }
}
</style>